<template>
	<view class="favorite_layout">
		<z-paging ref="paging" v-model="dataList" @query="queryList" show-refresher-when-reload>
			<view class="item" v-for="(item,index) in dataList" :key="item._id">
				<uni-circle-item v-if="item.circle" :circle="item.circle"></uni-circle-item>
				<zixun-list-item v-else :item="item.article"></zixun-list-item>
			</view>
		</z-paging>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue';

	import {
		onLoad
	} from '@dcloudio/uni-app'

	const paging = ref(null)
	const dataList = ref([])
	const favoriteObj = uniCloud.importObject('favoriteObj', {
		customUI: true
	})

	const queryList = async (pageNo, pageSize) => {
		let res = await favoriteObj.list(pageNo, pageSize)
		console.log("我的收藏", res)
		if (res.errCode != 0) {
			paging.value.complete(false)
			return
		}
		paging.value.complete(res.data)
	}

	// 点击了我的喜欢
	uni.$on('consult_is_like_emit', (params) => {
		let res = dataList.value.find(obj => obj.article._id == params._id)
		if (!res) {
			return
		}
		res.article.like_count = params.like_count
	})

	uni.$on('circle_is_like_emit', () => {
		if (!paging.value) {
			return
		}
		paging.value.reload()
	})
</script>

<style lang="scss">
	page {
		background-color: $me-color-background;
	}
</style>

<style lang="scss" scoped>
	.favorite_layout {}
</style>